﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Data;

namespace NJL.Web
{
    public partial class NewsList : BasePageVisitor
    {

        private readonly BLL.NJL_SYS_NEWS bllNews = new BLL.NJL_SYS_NEWS();
        private readonly BLL.NJL_SYS_CS_NEWS_TYPE bllNewsType = new BLL.NJL_SYS_CS_NEWS_TYPE();
        protected IList<Model.NJL_SYS_CS_NEWS_TYPE> LIST_NEWS_TYPE;
        protected string NEWS_TYPE_CODE;
        protected string NEWS_TYPE_NAME;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
            if (!IsPostBack)
            {
                ViewState["pager"] = "0";
                bind();
            }
            base.LoadPageSeoInformation(NEWS_TYPE_NAME);
        }
        private void LoadData()
        {
            if (Request.QueryString["keywords"] != null)
            {
                Page.Title = "乡村快报_农家乐网";
                typeName.Text = "搜索结果";
            }
            else
            {   

                NEWS_TYPE_CODE = Request.QueryString["id"];
                NEWS_TYPE_NAME = bllNewsType.GetModel(NEWS_TYPE_CODE).TYPE_NAME;
                LIST_NEWS_TYPE = bllNewsType.GetModelList(" TYPE_CODE>20");
                typeName.Text = NEWS_TYPE_NAME;
                Page.Title = "乡村快报_" + NEWS_TYPE_NAME + "_农家乐网";
            }
        }
        public void bind()
        {
            DataSet ds = new DataSet();
            if (Request.QueryString["keywords"] != null)
            {
                ds = bllNews.GetList("(a.NEWS_TITLE like '%" + Request.QueryString["keywords"] + "%' or a.NEWS_SUBJECT_TITLE like '%" + Request.QueryString["keywords"] + "%' or a.NEWS_TAG like '" + Request.QueryString + "') and (a.TYPE_CODE='20' or a.TYPE_CODE='35' or a.TYPE_CODE='36' or a.TYPE_CODE='37' or a.TYPE_CODE='38' or a.TYPE_CODE='31' or a.TYPE_CODE='32' or a.TYPE_CODE='33' or a.TYPE_CODE='34') and a.NJL_SYS_BASE_ID='" + WEBSITE_CODE + "'");

                if (ds.Tables[0].Rows.Count > 15)
                {
                    pager.InnerHtml = Royalsoft.Common.Pager.GetPageNum(ds, rptUserList, 15, new string[]{"keywords"});
                }
                else
                {
                    rptUserList.DataSource = ds;
                    rptUserList.DataBind();
                }
            }
            else
            {
                ds = bllNews.GetList("a.TYPE_CODE='" + NEWS_TYPE_CODE + "' and a.NJL_SYS_BASE_ID='"+WEBSITE_CODE+"'");
                if (ds.Tables[0].Rows.Count > 15)
                {
                    pager.InnerHtml = Royalsoft.Common.Pager.GetPageNum(ds, rptUserList, 15, new string[] { "id" }, "/xckb/" + ds.Tables[0].Rows[0]["TYPE_CODE"]+"/");
                }
                else
                {
                    rptUserList.DataSource = ds;
                    rptUserList.DataBind();
                }
            }
        }


    }
}